package com.burstly.lib.persistance;

import android.content.Context;
import com.burstly.lib.util.PrioritizedAsyncTask;
import java.io.Serializable;

public class ResponseSaver<T extends Serializable>
{
  private static final String LAST_RESPONSE_FOR = "last_response_for_";
  private volatile boolean mAllowedToLoad;
  private volatile boolean mAllowedToSave;
  final ObjectSaveLoadHandler<T> mFileHandler;
  private int mLastSavedHash;

  public ResponseSaver(Context paramContext, String paramString)
  {
    this.mFileHandler = new ObjectSaveLoadHandler(paramContext, "last_response_for_" + paramString);
  }

  public void deleteLastResponse()
  {
    this.mFileHandler.delete();
  }

  public boolean isAllowedToLoad()
  {
    return this.mAllowedToLoad;
  }

  public boolean isAllowedToSave()
  {
    return this.mAllowedToSave;
  }

  public T loadLastResponse()
  {
    try
    {
      boolean bool = this.mAllowedToLoad;
      Serializable localSerializable = null;
      if (bool)
      {
        localSerializable = this.mFileHandler.load();
        if (localSerializable != null)
          this.mLastSavedHash = localSerializable.hashCode();
      }
      return localSerializable;
    }
    finally
    {
    }
  }

  public void saveLastResponse(final T paramT)
  {
    try
    {
      if ((this.mAllowedToSave) && (paramT != null))
      {
        int i = paramT.hashCode();
        if (this.mLastSavedHash != i)
        {
          this.mLastSavedHash = i;
          new PrioritizedAsyncTask()
          {
            protected Void performInBackground()
            {
              ResponseSaver.this.mFileHandler.save(paramT);
              return null;
            }
          }
          .execute(new Void[0]);
          this.mAllowedToSave = false;
        }
      }
      return;
    }
    finally
    {
    }
  }

  public void setAllowedToLoad(boolean paramBoolean)
  {
    this.mAllowedToLoad = paramBoolean;
  }

  public void setAllowedToSave(boolean paramBoolean)
  {
    this.mAllowedToSave = paramBoolean;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.persistance.ResponseSaver
 * JD-Core Version:    0.6.2
 */